var _n86;
var cc__extends = __extends;
var cc__decorate = __decorate;
var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $1$EventManager = require("EventManager");
var s = cc__importDefault($1$EventManager);
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
cc__decorator.property;
var def_yyComponent = function (t) {
  function _ctor() {
    const instance = null !== t && t.apply(this, arguments) || this; // 调用函数 t，如果不存在则使用 this
    // 初始化自定义属性
    instance._customId = null;
    instance.events = {};
    instance.onceEvents = {};

    // 返回初始化后的实例
    return instance;
  }
  var o;
  cc__extends(_ctor, t);
  o = _ctor;
  Object.defineProperty(_ctor.prototype, "Id", {
    get() {
      null === this._customId && (this._customId = o._autoId++);
      return this._customId;
    },
    enumerable: false,
    configurable: true
  });
  _ctor.prototype.removeElementInArray = function (t, e) {
    const targetId = t.Id; // 获取对象 t 的 Id
    for (let n = 0; n < e.length; n++) {
      if (e[n].Id === targetId) { // 使用严格相等以避免类型不匹配
        e.splice(n, 1); // 删除该对象
        return true; // 返回删除成功
      }
    }
    return false; // 没有找到匹配的 Id，返回 false
  };
  _ctor.prototype.init = function (t) {
    this.initComponents();
    this.registAllCustomUpdate();
    this.onEvents();
    t && this.setData(t);
  };
  _ctor.prototype.initComponents = function () {
    if (this.node.parent) { // 检查节点是否有父级
      const widget = this.node.getComponent(cc.Widget); // 获取 Widget 组件
      widget?.updateAlignment(); // 如果存在，更新对齐

      const layout = this.node.getComponent(cc.Layout); // 获取 Layout 组件
      layout?.updateLayout(); // 如果存在，更新布局
    }
  };
  _ctor.prototype.onEvents = function () { };
  _ctor.prototype.registAllCustomUpdate = function () { };
  _ctor.prototype.reset = function () { };
  _ctor.prototype.setData = function () { };
  _ctor.prototype.reuse = function (t) {
    this.reset();
    this.onEvents();
    t && this.setData(t);
  };
  _ctor.prototype.unuse = function () {
    this.reset();
    this.offEvents();
  };
  Object.defineProperty(_ctor.prototype, "customUpdateState", {
    get() {
      return this._customUpdateState;
    },
    enumerable: false,
    configurable: true
  });
  _ctor.prototype.stepEmpty = function () { };
  _ctor.prototype.initCustomUpdateState = function () {
    this._customUpdateState = null;
    this.customStep = this.stepEmpty;
    this.customUpdateMap = {};
  };
  _ctor.prototype.resetCustomUpdateState = function () {
    this._customUpdateState = null;
    this.customStep = this.stepEmpty;
  };
  _ctor.prototype.registCustomUpdate = function (t, e) {
    this.customUpdateMap || (this.customUpdateMap = {});
    this.customUpdateMap[t] = e;
  };
  _ctor.prototype.enterCustomUpdateState = function (t) {
    if (this._customUpdateState !== t) { // 检查状态是否改变，使用严格相等
      this._customUpdateState = t; // 更新状态
      this.customStep = this.customUpdateMap[t] || this.stepEmpty; // 使用逻辑或简化赋值
    }
  };
  _ctor.prototype.customUpdate = function (t) {
    this.customStep && this.customStep(t);
  };
  _ctor.prototype.runCustomUpdate = function (t, e) {
    for (var o = t.length - 1; o >= 0; --o) {
      t[o].customUpdate(e);
    }
  };
  Object.defineProperty(_ctor.prototype, "x", {
    get() {
      return this.node.x;
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(_ctor.prototype, "y", {
    get() {
      return this.node.y;
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(_ctor.prototype, "z", {
    get() {
      return this.node.z;
    },
    enumerable: false,
    configurable: true
  });
  _ctor.prototype.setPosition = function (t) {
    this.node.setPosition(t);
  };
  _ctor.prototype.getPosition = function () {
    if (this.node.is3DNode) {
      return cc.v3(this.x, this.y, this.z);
    } else {
      return cc.v3(this.x, this.y);
    }
  };
  Object.defineProperty(_ctor.prototype, "angleX", {
    get() {
      return this.node.eulerAngles.x;
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(_ctor.prototype, "angleY", {
    get() {
      return this.node.eulerAngles.y;
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(_ctor.prototype, "angleZ", {
    get() {
      return this.node.eulerAngles.z;
    },
    enumerable: false,
    configurable: true
  });
  _ctor.prototype.setEulerAngles = function (t) {
    this.node.eulerAngles = t;
  };
  _ctor.prototype.setScale = function (t) {
    this.node.setScale(t);
  };
  _ctor.prototype.show = function (t) {
    this.node.active = true;
    t && this.setData(t);
  };
  _ctor.prototype.hide = function () {
    this.node.active = false;
  };
  _ctor.prototype.getData = function () {
    return null;
  };
  _ctor.prototype.on = function (t, e, o) {
    var n = s.default.on(t, e, o);
    if (n) {
      this.events.hasOwnProperty(t) || (this.events[t] = []);
      this.events[t].push(n);
    }
  };
  _ctor.prototype.once = function (t, e, o) {
    var n = s.default.once(t, e, o);
    if (n) {
      this.onceEvents.hasOwnProperty(t) || (this.onceEvents[t] = []);
      this.onceEvents[t].push(n);
    }
  };
  _ctor.prototype.off = function (t, e, o) {
    const removeCallbacks = (eventsList) => {
      for (let i = eventsList.length - 1; i >= 0; --i) {
        if (eventsList[i].cb === e && eventsList[i].target === o) {
          s.default.off(t, eventsList[i]); // 移除事件侦听
          eventsList.splice(i, 1); // 从列表中移除该回调
        }
      }
    };

    const eventList = this.events[t]; // 获取事件中的回调列表
    if (eventList) {
      removeCallbacks(eventList); // 移除普通事件的回调
    }

    const onceEventList = this.onceEvents[t]; // 获取一次性事件中的回调列表
    if (onceEventList) {
      removeCallbacks(onceEventList); // 移除一次性事件的回调
    }
  };
  _ctor.prototype.emit = function (t, e, o, n, i, r) {
    const args = [t];

    // 将已定义的参数加入到 args 数组中
    if (e !== undefined) args.push(e);
    if (o !== undefined) args.push(o);
    if (n !== undefined) args.push(n);
    if (i !== undefined) args.push(i);
    if (r !== undefined) args.push(r);

    // 使用扩展运算符发射事件
    s.default.emit(...args);

    // 删除一次性事件
    if (this.onceEvents.hasOwnProperty(t)) {
      delete this.onceEvents[t];
    }
  };
  _ctor.prototype.offEvents = function () {
    for (var t in this.events) {
      s.default.offGroup(t, this.events[t]);
    }
    this.events = {};
    for (var t in this.onceEvents) {
      s.default.offGroup(t, this.onceEvents[t]);
    }
    this.onceEvents = {};
  };
  _ctor.prototype.onDestroy = function () {
    this.offEvents();
  };
  _ctor._autoId = 1;
  return o = cc__decorate([ccp_ccclass], _ctor);
}(cc.Component);
exports.default = def_yyComponent;